//
//  HNSH_MineViewOrderCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/27.
//

#import "HNSH_MineViewOrderCell.h"

@interface HNSH_MineViewOrderCell ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;

@end


@implementation HNSH_MineViewOrderCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self.contentView addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.top.bottom.mas_equalTo(0);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(17, 14, 200, 22)];
    titleLabel.text = @"商品订单";
    titleLabel.textColor = [UIColor appBlackLabelColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.bgView addSubview:titleLabel];
    
    UILabel *desLabel = [[UILabel alloc]init];
    desLabel.text = @"全部订单";
    desLabel.textColor = [UIColor appGray666LabelColor];
    desLabel.font = [UIFont systemFontOfSize:12];
    [self.bgView addSubview:desLabel];
    [desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-29);
        make.height.mas_equalTo(22);
        make.centerY.equalTo(titleLabel.mas_centerY);
    }];
    
    UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenWidth-24)-27, 19, 12, 12)];
    imgV.image = [UIImage imageNamed:@"mine_order_show_icon"];
    [self.bgView addSubview:imgV];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, kScreenWidth-40, 50);
    button.backgroundColor = [UIColor clearColor];
    button.tag = 0;
    [self.bgView addSubview:button];
    WeakSelf(weakSelf);
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        UIButton *selectButton = x;
        if (weakSelf.orderBlock) {
            weakSelf.orderBlock(selectButton.tag);
        }
    }];
    
    
    NSArray *titles = @[@"待付款",@"待收货",@"已完成",@"已取消",@"售后"];
    CGFloat width = (kScreenWidth - 24)/titles.count;
    for (int i = 1; i <= titles.count; i ++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(width*(i-1), 54, width, 58);
        [button setTitle:titles[i-1] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor appGray666LabelColor] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"mine_order_%d",i]] forState:UIControlStateNormal];
        [self.bgView addSubview:button];
        [button HNSH_layoutButtonWithEdgeInsetsStyle:HHZXButtonStyleTextBottom imageTitleSpace:4];
        button.tag = i;
        [[button rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
            UIButton *selectButton = x;
            if (weakSelf.orderBlock) {
                weakSelf.orderBlock(selectButton.tag);
            }
        }];
    }
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
        _bgView.layer.cornerRadius = 8.0f;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}


@end
